package per.dg.retrofittestkotlin.project

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.Observer
import per.dg.retrofittestkotlin.databinding.ActivityHomeBinding
import per.dg.retrofittestkotlin.project.home.HomeArticleListAdapter
import per.dg.retrofittestkotlin.project.home.HomeViewModel
import per.dg.retrofittestkotlin.project.model.Article

class HomeActivity : AppCompatActivity() {

    private lateinit var homeBinding: ActivityHomeBinding

    private val homeViewModel : HomeViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        homeBinding = ActivityHomeBinding.inflate(layoutInflater)
        setContentView(homeBinding.root)

//        homeViewModel.homeArticleListLiveData.observe(this, Observer(adapter::submitList))
        homeViewModel.homeArticleListLiveData.observe(this, object : Observer<MutableList<Article>>{
            override fun onChanged(t: MutableList<Article>?) {
                homeBinding.rvHomeArticleList.adapter = HomeArticleListAdapter(t)
            }

        })

        homeViewModel.getHomeArticleList(0)

    }
}